from bipy.components import Component
from psp2d import Screen, Color

class PSPScreen(Component):
    def __init__(self, color = (0, 0, 0)):
        super(PSPScreen, self).__init__('screen', 100)
        self.__screen = Screen()
        self.__clear = Color(*color)
        
    def swap(self):
        self.__screen.swap()
        
    def clear(self):
        self.__screen.clear( self.__clear )
        
    #def draw_line(x0, y0, x1, y1, color):
    #    self.__screen.drawLine(x0, y0, x1, y1, color)
        
    #def write_line(x, y, text, color):
    #    self.__screen.write_line(x, y, text, color)
    
    def draw_text(self, font, x, y, string):
        font.drawText(self.__screen, x, y, string)
    
    def blit(self, source, sx = 0, sy = 0, w = -1, h = -1, dx = 0, dy = 0, blend = False, dw = -1, dh = -1):
        self.__screen.blit(source, sx = sx, sy = sy, w = w, h = h, dx = dx, dy = dy, blend = blend, dw = dw, dh = dh)
        
component_class = PSPScreen